var url="";
var model;
var request;
var Dang;
var result=false;
function LoadData(){
    result = false;
    request.post('http://'+url+'/app/ProjectDetail!ajaxProjectDetails?projectId='+GetQueryString('projectId')).success(function(data){
        // if(data!=null&&data.length==0){
        //    $("#body").html("<div style='margin:100px auto;width:200px;height:100px;position: relative;text-align:center;'><img  style='position: relative;' src='image/nodata.png' width='62' height='66'/><br/><span style='font-size:14px;color:rgb(141,141,141);'>没有相关内容!</span></div>");
        //  }else
        //  {
        //  }
        console.log(data);
        model.detail=data;
        model.day.day1 ={'width':data.dayWidth1+'%'};
        model.day.day2 ={'width':data.dayWidth2+'%'};
        model.day.day3 ={'width':data.dayWidth3+'%'};
        var dsa =model.getcalColor(data.dayWidth1,data.dayWidth2,data.dayWidth3,data.dayEnergyPercent);
        model.day.day4 ={'width':data.dayEnergyPercent+'%','background':dsa};
        model.day.day5={'color':dsa};

        model.month.month1 ={'width':data.monthWidth1+'%'};
        model.month.month2 ={'width':data.monthWidth2+'%'};
        model.month.month3 ={'width':data.monthWidth3+'%'};
        dsa = model.getcalColor(data.monthWidth1,data.monthWidth2,data.monthWidth3,data.monthEnergyPercent);
        model.month.month4 ={'width':data.monthEnergyPercent+'%','background':dsa};
        model.month.month5={'color':dsa};
        model.year.year1 ={'width':data.yearWidth1+'%'};
        model.year.year2 ={'width':data.yearWidth2+'%'};
        model.year.year3 ={'width':data.yearWidth3+'%'};
        dsa = model.getcalColor(data.yearWidth1,data.yearWidth2,data.yearWidth3,data.yearEnergyPercent);
        model.year.year4 ={'width':data.yearEnergyPercent+'%','background':dsa};
        model.year.year5={'color':dsa};

        var colors = data.copLevels.split(",");
        model.cop1 = {'width':colors[0]+'%'};
        model.cop2 = {'width':colors[1]+'%'};
        model.cop3 = {'width':colors[2]+'%'};
        model.cop4 = {'width':colors[3]+'%'};
         var dds = model.getcalColor2(colors[0],colors[1],colors[2],colors[3],data.cop);
             model.coppostion = {
        'left': window.innerWidth * 0.84 * (data.cop/10)-9.5 +'px'
    };
        model.cop5 = {'color':dds};
        result = true;
         }).error(function(data,status,headers,config){
      if((status>=200&&status<300)||status===304||status===1223||status===0){
      $("body").html("网络访问出错！");
      }
      });
}

(function(){
	var app=angular.module('Dang',[ ]);
	app.controller('DangController',['$http','$window',function($http,$window){
     Dang=this;
		request=$http;
    model=Dang;
    url='120.26.110.125/jncloud';
    bindEvent();
    var dsa  = GetQueryString('projectId');
    LoadData();

    Dang.day = {
                 'day1':{'width':'33%'},
                 'day2':{'width':'33%'},
                 'day3':{'width':'34%'},
                 'day4':{'width':'50%'},
                 'day5':{'color':'black'}
                };
     Dang.month = {
               'month1':{'width':'33%'},
               'month2':{'width':'33%'},
               'month3':{'width':'34%'},
               'month4':{'width':'50%'},
               'month5':{'color':'black'}
              }; 
    Dang.year = {
                 'year1':{'width':'33%'},
                 'year2':{'width':'33%'},
                 'year3':{'width':'34%'},
                 'year4':{'width':'50%'},
                 'year5':{'color':'black'}
                }; 

    Dang.getcalColor=function(a,b,c,d){
         var d1 = Number(d);
         var a1 = Number(a);
         var b1 = Number(b);
         var c1 = Number(c);
         if(d1<=a1)  return '#33b24b';
         else if(d1>a1&&d1<=(a1+b1)) return '#ffcc00';
         else if(d1>(a1+b1)&&d1<=(a1+b1+c1)) return '#ff333b';
    }

    Dang.getcalColor2=function(a,b,c,d,e)
    {
         var d1 = Number(d);
         var a1 = Number(a);
         var b1 = Number(b);
         var c1 = Number(c);
         var e1 = Number(e)*10;
         if(e1<=a1) {Dang.copjpg = 'arr1.png';return '#33b24b';} 
         else if(e1>a1&&e1<=(a1+b1)) {
           Dang.copjpg = 'arr2.png';
          return '#ffcc00';
         }
         else if(e1>(a1+b1)&&e1<=(a1+b1+c1)) {
           Dang.copjpg = 'arr3.png';
          return '#ff333b';
         } 
         else if(e1>(a1+b1+c1)&&e<=(a1+b1+c1+d1)){
           Dang.copjpg = 'arr4.png';
           return '#5cc9ff';
         } 

    }

    Dang.copjpg = 'arr2.png';
    Dang.cop5 = {'color':'#33b24b'}

	}]);
})();
